<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopCommissionGoodsTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_commission_goods', ['comment' => '分销商品', 'engine' => 'InnoDB', 'id' => false, 'primary_key' => 'goods_id', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('goods_id', 'integer', ['limit'  =>  11, 'null' => false, 'default' => 0, 'comment' => '分销商品'])
            ->addColumn(Column::tinyInteger('self_rules')->setNull(true)->setDefault(0)->setComment('独立设置佣金:0=否,1=是'))
            ->addColumn('commission_rules', 'text', ['null' => true, 'comment' => '佣金设置'])
            ->addColumn(Column::tinyInteger('status')->setComment('状态:0=不参与分销,1=参与分销'))
            ->addColumn('commission_config', 'text', ['null' => true, 'comment' => '独立佣金规则'])
            ->addColumn(Column::tinyInteger('commission_order_status')->setDefault(1)->setComment('是否计入业绩:0=否,1=是'))
            ->addIndex('goods_id', ['unique' => true])
            ->create();
    }


    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_commission_goods');
        $table->drop();
    }
}
